'use strict';

/* Controllers */
// signin controller
app.controller('AccountinfoController', ['$scope', '$state', '$stateParams', '$cookieStore', 'StoreService','dbUtils', function ($scope, $state, $stateParams, $cookieStore, storeService,dbUtils) {

    storeService.getBankinfo().then(function(response){
        $scope.info = response.data;
        if($scope.info && $scope.info.bank){
            $scope.hasSet = true;
        }
    });

    storeService.getBanks().then(function(response){
        $scope.banks = response.data;
    });


    $scope.submit = function () {
        if($scope.bankForm.$invalid){
            return;
        }
        storeService.setBankinfo({
            bank:$scope.info.bank,
            bankNo:$scope.info.bankNo,
            bankMaster:$scope.info.bankMaster
        }).then(function(response){
            if (response.code == 0) {
                dbUtils.success("设置成功！","提示");
                $scope.hasSet = true;
            } else {
                dbUtils.error(response.message,"提示");
            }
        });
    }

    $scope.cash = function(){
        if($scope.cashForm.$invalid){
            return;
        }
        storeService.applyCash($scope.money*100,$scope.password).then(function(response){
            dbUtils.error(response.message,"提示");
        });
    }
}])
;